﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace Hsenl.Network {
    public class TcpSocket {
        private TcpReceiver _receiver;
        private TcpSender _sender;
        
        public TcpReceiver Receiver => this._receiver;
        public TcpSender Sender => this._sender;

        public void AddReceiver(TcpReceiver receiver) {
            this._receiver = receiver;
        }

        public void AddSender(TcpSender sender) {
            this._sender = sender;
        }

        public bool ReceiveAsync() {
            return this._receiver?.ReceiveAsync() ?? false;
        }

        public bool SendAsync() {
            return this._sender?.SendAsync() ?? false;
        }

        public void Close() {
            this._receiver?.Close();
            this._sender?.Close();
            this._receiver = null;
            this._sender = null;
        }

        public void Dispose() {
            this._receiver?.Dispose();
            this._sender?.Dispose();
            this._receiver = null;
            this._sender = null;
        }
    }
}